package cc.bukkitPlugin.banitem.command.analyse;

import java.util.ArrayList;
import java.util.Arrays;

import org.bukkit.command.CommandSender;

import cc.bukkitPlugin.banitem.BanItem;
import cc.bukkitPlugin.banitem.BanItemEnume.ListType;
import cc.bukkitPlugin.banitem.CFG;
import cc.bukkitPlugin.banitem.command.AParamCommand;

public class ParamListType extends AParam{

    /**所有可能的值,确保小写*/
    private ArrayList<String> mValidValue=new ArrayList<>();

    public ParamListType(BanItem pPlugin,AnalyseMan pAnalyor){
        super(pPlugin,pAnalyor);
        this.mLabels=new String[]{"t","type"};
        for(ListType sType : ListType.values())
            this.mValidValue.add(sType.name().toLowerCase());
    }

    @Override
    public AnalyseResult handle(CommandSender pSender,AnalyseResult pCmdParam,String pArg){
        pCmdParam.mListType=ListType.getTypeByEnumeName(pArg);
        if(pCmdParam.mListType==null)
            return pCmdParam.buildError("未知的列表类型["+pArg+"],可选值有"+this.mValidValue);
        return pCmdParam.buildSuccess();
    }

    @Override
    public ArrayList<String> tabComplete(CommandSender pSender,AParamCommand pCommand,String[] pArgs){
        ArrayList<String> list=new ArrayList<>();
        if(pArgs==null||pArgs.length==0)
            return list;
        String[] params=pArgs[pArgs.length-1].split(":",2);
        String tLabel=params[0]+":";
        String part="";
        if(params.length==2)
            part=params[1].toLowerCase();
        for(String sKey : this.mValidValue){
            if(sKey.startsWith(part)){
                list.add(tLabel+sKey);
                if(list.size()>=100)
                    return list;
            }
        }
        return list;
    }

    @Override
    public ArrayList<String> getHelp(){
        ArrayList<String> help=new ArrayList<>();
        help.add(CFG.cmd_color+"  "+Arrays.toString(this.mLabels));
        help.add(CFG.help_color+"    设置操作的列表类型");
        help.add(CFG.help_color+"    可选值有"+this.mValidValue);
        return help;
    }

}
